<?php

Class Recipe extends CI_Model
{
  function getAllRecipes($breakfast, $lunch, $dinner)
  {
    $this->db->select('*');
    $this->db->from('RecipeEC');
    $this->db->where('breakfast',$breakfast);
    $this->db->where('lunch',$lunch);
    $this->db->where('dinner',$dinner);
    
	$query = $this->db->get();
    
    if($query -> num_rows() > 0)
    {
      return $query->result();
    }
    else
    {
      return false;
    }    
  }
  
  
  function getBreakfast($lactose, $gluten, $meat){
      
        //$query = $this->db->query("SELECT * FROM RecipeEC WHERE  breakfast= 1 AND idRecipe NOT IN (SELECT idRecipe FROM IngredientEC WHERE hasLactose=? OR hasGluten=? OR hasMeat=?)", $gluten, $lactose, $meat); 
        
        
        $sql = "SELECT * FROM RecipeEC WHERE  breakfast= 1 AND idRecipe NOT IN (SELECT idRecipe FROM IngredientEC WHERE hasLactose=? AND hasGluten=? AND hasMeat=?)"; 

        $query = $this->db->query($sql, array($lactose, $gluten, $meat));
        
        return $query->result_array();                       
  }
  
  
   function getLunch($lactose, $gluten, $meat){
      
        //$query = $this->db->query("SELECT * FROM RecipeEC WHERE  breakfast= 1 AND idRecipe NOT IN (SELECT idRecipe FROM IngredientEC WHERE hasLactose=? OR hasGluten=? OR hasMeat=?)", $gluten, $lactose, $meat); 
        
        
        $sql = "SELECT * FROM RecipeEC WHERE  lunch= 1 AND idRecipe NOT IN (SELECT idRecipe FROM IngredientEC WHERE hasLactose=? AND hasGluten=? AND hasMeat=?)"; 

        $query = $this->db->query($sql, array($lactose, $gluten, $meat));
        
        return $query->result_array();                       
  }
  
  
  
   function getDinner($lactose, $gluten, $meat){
      
        //$query = $this->db->query("SELECT * FROM RecipeEC WHERE  breakfast= 1 AND idRecipe NOT IN (SELECT idRecipe FROM IngredientEC WHERE hasLactose=? OR hasGluten=? OR hasMeat=?)", $gluten, $lactose, $meat); 
        
        
        $sql = "SELECT * FROM RecipeEC WHERE  dinner= 1 AND idRecipe NOT IN (SELECT idRecipe FROM IngredientEC WHERE hasLactose=? AND hasGluten=? AND hasMeat=?)"; 

        $query = $this->db->query($sql, array($lactose, $gluten, $meat));
        
        return $query->result_array();                       
  }
  
  
  
  
  
  
  
}
?>
